package microframe.ui
{
	import com.greensock.TweenMax;
	import com.ux.event.EventObserver;
	import com.ux.manager.StageManager;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import microframe.event.EventType;
	
	
	/**
	 * @author winnie
	 */	
	public class ContentsContainer extends Sprite
	{
		
		/** main container return **/
		public static function get container():ContentsContainer
		{
			if( _container == null ) _container = new ContentsContainer();
			return _container;
		}
		
		
		private static var _container : ContentsContainer;
		private var application : DisplayObjectContainer;
		private var blackDim : Sprite;
		private var blurDim : Bitmap;
		
		
		/**
		 * ContentsContainer
		 */		
		public function ContentsContainer()
		{
			super();
		}
		
		
		public function makeDim():void
		{
			blackDim = new Sprite();
			this.addChild( blackDim );
			
			blackDim.graphics.beginFill( 0x000000, 1 );
			blackDim.graphics.drawRect( 0,0,StageManager.stage.stageWidth, StageManager.stage.stageHeight );
			blackDim.graphics.endFill();
			blackDim.alpha = 0;
			blackDim.visible = false;
			
			EventObserver.instance.addEventListener( EventType.DIM_ON, onDimOn );
			EventObserver.instance.addEventListener( EventType.DIM_OFF, onDimOff );
		}
		
		private function onDimOn(e:Event=null):void
		{
			blackDim.width = StageManager.stage.stageWidth;
			blackDim.height = StageManager.stage.stageHeight;
			_container.setChildIndex( blackDim, _container.numChildren-1 );

			_container.mouseChildren = false;
			_container.mouseEnabled = false;
			TweenMax.to( blackDim, 0.5, {autoAlpha:0.6} );
		}
		
		private function onDimOff( e:Event ):void
		{
			_container.mouseChildren = true;
			_container.mouseEnabled = true;
			
			TweenMax.to( blackDim, 0.5, {autoAlpha:0} );
		}
		
	}
}